package tongcheng.com.tongcheng.base.main.gerencenter;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.load.resource.bitmap.CircleCrop;

import butterknife.Bind;
import butterknife.ButterKnife;
import tongcheng.com.tongcheng.ConStans;
import tongcheng.com.tongcheng.R;
import tongcheng.com.tongcheng.base.BaseFragment;
import tongcheng.com.tongcheng.base.main.FragmentOrder;
import tongcheng.com.tongcheng.base.main.activity.GeRenXinxiActivity;
import tongcheng.com.tongcheng.base.main.activity.MessageActivity;
import tongcheng.com.tongcheng.base.main.activity.SettingActivity;
import tongcheng.com.tongcheng.base.main.activity.WebViewActivity;
import tongcheng.com.tongcheng.base.main.activity.WoDeQianBaoActivity;
import tongcheng.com.tongcheng.base.xinyong.XinYongFenActivity;
import tongcheng.com.tongcheng.ui.yemian.shenfen.activity.install.InstallPeopleListActivity;
import tongcheng.com.tongcheng.utils.GlideApp;
import tongcheng.com.tongcheng.utils.Setting;

import static tongcheng.com.tongcheng.base.main.gerencenter.GeRenQiangdanPersonCenterActivity.mMainRb2;
import static tongcheng.com.tongcheng.base.main.gerencenter.GeRenQiangdanPersonCenterActivity.mMainRg;

/**
 * Created by P on 2017/7/14.
 * 个人抢单-个人中心
 */

public class GerenFragmentPerson extends BaseFragment {
    @Bind(R.id.back)
    ImageView mBack;
    @Bind(R.id.title)
    TextView mTitle;
//    @Bind(R.id.line)
//    View mLine;
    @Bind(R.id.title_bar)
    RelativeLayout mTitleBar;
    @Bind(R.id.person_icon)
    ImageView mPersonIcon;
    @Bind(R.id.person_ll1)
    LinearLayout mPersonLl1;
    @Bind(R.id.person_qianbao)
    LinearLayout mPersonQianbao;
    @Bind(R.id.person_orderlist)
    LinearLayout mPersonOrderlist;
    @Bind(R.id.person_install)
    LinearLayout mPersonInstall;
    @Bind(R.id.person_ll2)
    LinearLayout mPersonLl2;
    @Bind(R.id.person_message)
    LinearLayout mPersonMessage;
    @Bind(R.id.person_setting)
    LinearLayout mPersonSetting;
    @Bind(R.id.person_name)
    TextView mPersonName;
    @Bind(R.id.person_jifen)
    Button mPersonJifen;
    @Bind(R.id.person_money)
    TextView mPersonMoney;
    @Bind(R.id.title_icons)
    ImageView title_icons;
    @Bind(R.id.ll_yongHuZhiNan)
    LinearLayout ll_yongHuZhiNan;
    @Bind(R.id.ll_yaoQingHaoYou)
    LinearLayout ll_yaoQingHaoYou;

    @Override
    public void FragmentStart() {

    }

    @Override
    public Integer setFragmentView() {
        return R.layout.fragment_gerenperson;
    }

    @Override
    public void onResume() {
        super.onResume();
        GlideApp.with(this).load(ConStans.BaseUrl_Test_url + Setting.getTouXiang()).into(title_icons);
        GlideApp.with(this).load(ConStans.BaseUrl_Test_url + Setting.getTouXiang()).transform(new CircleCrop()).into(mPersonIcon);
        mPersonName.setText(Setting.getUserName() + "");
        mPersonMoney.setText(Setting.getYuE() + "");
        mPersonJifen.setText("信用积分:"+Setting.getXinYongFen()+">");
    }

    @Override
    public void FragmentCreate(View inflate) {
        ButterKnife.bind(this, inflate);
        settitlebar(mTitleBar);
        mTitleBar.setBackgroundColor(0x00ffffff);
        mBack.setVisibility(View.VISIBLE);
        mTitle.setText("个人中心");
        mTitle.setTextColor(Color.WHITE);
//        mLine.setVisibility(View.INVISIBLE);
        mPersonName.setText(Setting.getUserName());
        mPersonJifen.setText("信用积分:"+Setting.getXinYongFen()+">");
        GlideApp.with(this).load(ConStans.BaseUrl_Test_url + Setting.getTouXiang()).into(title_icons);
        GlideApp.with(this).load(ConStans.BaseUrl_Test_url + Setting.getTouXiang()).transform(new CircleCrop()).into(mPersonIcon);

        mPersonMoney.setText(Setting.getYuE() + "");

        //返回
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getActivity().finish();
            }
        });

        //信用积分
        mPersonJifen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startactivity(mContext, XinYongFenActivity.class);
            }
        });

        //头像
        mPersonIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startactivity(getContext(), GeRenXinxiActivity.class);
            }
        });

        //我的钱包
        mPersonQianbao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startactivity(getContext(), WoDeQianBaoActivity.class);
            }
        });

        //我的订单
        mPersonOrderlist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Intent mIntent = new Intent(getContext(), GeRenQiangdanPersonCenterActivity.class);
//                mIntent.putExtra("bool",true);
//                mIntent.putExtra("yincang",true);
//                mContext.sendBroadcast(mIntent);
                mMainRb2.setChecked(true);
                mMainRg.setVisibility(View.GONE);
                FragmentTransaction transactions = getChildFragmentManager().beginTransaction();
                transactions.replace(R.id.main_fragment, new FragmentOrder());
                transactions.commit();

            }
        });
        //用户指南
        ll_yongHuZhiNan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent xnIntent = new Intent(mContext,WebViewActivity.class);
                xnIntent.putExtra("title","用户指南");
                xnIntent.putExtra("keyword",10);
                startActivity(xnIntent);
            }
        });
        //设置
        mPersonSetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent xnIntent = new Intent(mContext,SettingActivity.class);
                xnIntent.putExtra("yongHuXieYi",3);
                mContext.startActivity(xnIntent);

//                startactivity(getContext(), SettingActivity.class);
            }
        });

        //我的消息
        mPersonMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startactivity(getContext(), MessageActivity.class);
            }
        });


        mPersonLl2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });


        //安装人员
        mPersonInstall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startactivity(getContext(), InstallPeopleListActivity.class);
            }
        });

        ll_yaoQingHaoYou.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showShare();
            }
        });
    }



    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }
}
